package com.hometeacher.api.controller;

import com.alibaba.fastjson.JSONObject;
import com.hometeacher.api.model.StuList;
import com.hometeacher.api.model.TeacherList;
import com.hometeacher.api.service.TeacherService;
import com.hometeacher.api.util.Json;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.LinkedHashMap;

/**
 * @author ZhaoYuan
 * @data 03/04/2020 21:16
 */
@CrossOrigin
@RestController
@RequestMapping(value = "/teacher",method = RequestMethod.GET)
@Slf4j
public class TeacherController {

    @Autowired
    private TeacherService teacherService;

    @Autowired
    private Json json;

    @GetMapping("/allInfo")
    public LinkedHashMap<String, Object> getAllTeacherBaseInfo(HttpServletRequest httpServletRequest) {
        return json.getJson("teacherList",teacherService.findAllTeacherInfo());
    }

    @PostMapping(value = "/change")
    public  Object change(@RequestBody TeacherList teacherList){
        JSONObject jsonObject = new JSONObject();
        TeacherList teacherListForBase = teacherService.save(teacherList);
        if (teacherListForBase == null){
            jsonObject.put("message","error");
        } else {
            jsonObject.put("message","ok");
        }
        return jsonObject;
    }


}
